package com.training.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.training.admin.entity.principal.Principal;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface PrincipalDao {

    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM Principal where disabled = false")
    public int count();

    /**
     * 
     * @return
     */
    @Query("SELECT COUNT(*) FROM Principal where disabled = false AND email = :email ")
    public int countByEmail(@Variable("email") String email);

    /**
     * @param authority
     * @return
     */
    @Query("FROM Principal WHERE authority = :authority")
    public List<Principal> listSaleUser(@Variable("authority") String authority);

    /**
     * 
     * @param name
     * @return
     */
    @Query("FROM Principal WHERE disabled = false AND name = :name")
    public Principal load(@Variable("name") String name);
    /**
     * 
     * @param username
     * @return
     */
    @Query("FROM Principal WHERE disabled = false AND email = :email")
    public Principal loadByEmail(@Variable("email") String email);

    @Limit
    @Query("FROM Principal")
    public List<Principal> listByPage(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

}
